package com.android.qjpmc.widget.manager;

import android.content.Context;

import com.android.qjpmc.manager.AccountManager;
import com.android.qjpmc.widget.utils.SharedPrefsUtils;
import com.android.qjpmc.widget.utils.UIUtils;

/**
 * Created by Mloong on 2018/8/2.
 */

public class SPManager {
    public static class UserData {
        public static void saveUserInfo(Context context, String userJsonData) {
            SharedPrefsUtils.setStringPreference(context, "userInfo", userJsonData);
        }

        public static String getUserInfo(Context context) {

            return SharedPrefsUtils.getStringPreference(context, "userInfo");
        }


        public static void saveLoginData(Context context, String loginInfoBeanString) {
            SharedPrefsUtils.setStringPreference(context, "loginData", loginInfoBeanString);
        }

        public static String getLoginData(Context context) {
            if (context == null) context = UIUtils.getContext();
            return SharedPrefsUtils.getStringPreference(context, "loginData");
        }
    }

    public static class AgreementSplashData {
        public static void saveAgreementStatus(boolean b) {
            SharedPrefsUtils.setBooleanPreference("saveAgreementStatus", b);

        }

        public static boolean getAgreementStatus() {
            return SharedPrefsUtils.getBooleanPreference("saveAgreementStatus", false);

        }
    }

    public static class BaseUrlConfigData {
        public static String getBaseUrl(Context context) {
            return SharedPrefsUtils.getStringPreference(context, "baseUrl");

        }

        public static boolean setBaseUrl(String url) {
            return SharedPrefsUtils.setStringPreference("baseUrl", url);

        }
    }

    public static class CourseData {
        public static void saveCoursePlayProgress(long id, long playPosition) {
            SharedPrefsUtils.setLongPreference(AccountManager.getInstance().getUserId() + "CoursePlayProgres" + id, playPosition);
        }

        public static long getCoursePlayProgress(long id) {
            return SharedPrefsUtils.getLongPreference(AccountManager.getInstance().getUserId() + "CoursePlayProgres" + id, 0L);
        }
    }

    public static class HomeworkAnswer {
        public static void saveAnswerContent(long id, String content) {
            SharedPrefsUtils.setStringPreference(AccountManager.getInstance().getUserId() + "saveAnswerContent" + id, content);

        }

        public static String getAnswerContent(Context context, long id) {
            return SharedPrefsUtils.getStringPreference(context, AccountManager.getInstance().getUserId() + "saveAnswerContent" + id);

        }
    }

    public static class PublicTimeLimitPlay {
        public static void savePublicTimeLimitPlay(long id, int time) {
            SharedPrefsUtils.setIntegerPreference(AccountManager.getInstance().getUserId() + "savePublicTimeLimitPlay" + id, time);

        }

        public static int getPublicTimeLimitPlay(long id) {
            return SharedPrefsUtils.getIntegerPreference(AccountManager.getInstance().getUserId() + "savePublicTimeLimitPlay" + id, 0);

        }
    }

    public static class LoginInfo {
        public static void saveLoginInfo(String userName) {
            SharedPrefsUtils.setStringPreference("userName", userName);

        }

        public static String getLoginInfo() {
            return SharedPrefsUtils.getStringPreference(UIUtils.getContext(), "userName");

        }
    }
}
